package com.palfund.service;

import android.app.IntentService;
import android.content.Intent;
import android.os.SystemClock;
import android.support.annotation.Nullable;
import android.util.Log;

/**
 * Created by clvc on 2017/8/6.
 * 真正的速度是看不见的 !
 * Today is today , we will go !
 */

public class CustomIntentService extends IntentService {
    // 必须要有一个无参的构造方法!
    public CustomIntentService() {
        super("");
        Log.i("CustomIntentService", "---CustomIntentService()--->" + "  " + Thread.currentThread
                ().getName());
    }

    public CustomIntentService(String name) {
        super(name);
        Log.i("CustomIntentService", "---CustomIntentService()--->" + "name" + Thread
                .currentThread().getName());
    }

    @Override
    public void onCreate() {
        super.onCreate();
        Log.i("CustomIntentService", "---onCreate()--->" + Thread.currentThread().getName());
    }

    // 该方法属于worker thread,当该方法把所有的intent处理完成后,会自动停止自身,不需要我们手动调用stopSelf()方法.
    @Override
    protected void onHandleIntent(@Nullable Intent intent) {
        String info = intent.getStringExtra("info");
        Log.i("CustomIntentService", "---onHandleIntent()--->" + info + Thread.currentThread()
                .getName());
        SystemClock.sleep(3000);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.i("CustomIntentService", "---onDestroy()--->" + Thread.currentThread().getName());
    }
}
